home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Event.java < prev    next >
Text File  |  1998-09-22  |  25KB  |  835 lines

  1. /*
  2.  * @(#)Event.java    1.58 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.awt.event.*;
  17. import java.io.*;
  18.  
  19. /**
  20.  * <code>Event</code> is a platform-independent class that  
  21.  * encapsulates events from the platform's Graphical User 
  22.  * Interface in the Java 1.0 event model. In Java 1.1 
  23.  * and later versions, the <code>Event</code> class is maintained 
  24.  * only for backwards compatibilty. The information in this
  25.  * class description is provided to assist programmers in
  26.  * converting Java 1.0 programs to the new event model.
  27.  * <p>
  28.  * In the Java 1.0 event model, an event contains an 
  29.  * <a href="#id"><code>id</code></a> field 
  30.  * that indicates what type of event it is and which other 
  31.  * <code>Event</code> variables are relevant for the event.
  32.  * <p>
  33.  * For keyboard events, <a href="#key"><code>key</code></a> 
  34.  * contains a value indicating which key was activated, and 
  35.  * <a href="#modifiers"><code>modifiers</code></a> contains the 
  36.  * modifiers for that event.  For the KEY_PRESS and KEY_RELEASE  
  37.  * event ids, the value of <code>key</code> is the unicode 
  38.  * character code for the key. For KEY_ACTION and 
  39.  * KEY_ACTION_RELEASE, the value of <code>key</code> is
  40.  * one of the defined action-key identifiers in the 
  41.  * <code>Event</code> class (<code>PGUP</code>,  
  42.  * <code>PGDN</code>, <code>F1</code>, <code>F2</code>, etc).
  43.  *
  44.  * @version 1.58 07/01/98
  45.  * @author     Sami Shaio
  46.  * @since      JDK1.0
  47.  */
  48. public class Event implements java.io.Serializable {
  49.     private transient int data;
  50.  
  51.     /* Modifier constants */
  52.  
  53.     /**
  54.      * This flag indicates that the Shift key was down when the event 
  55.      * occurred. 
  56.      * @since   JDK1.0
  57.      */
  58.     public static final int SHIFT_MASK        = 1 << 0;
  59.  
  60.     /**
  61.      * This flag indicates that the Control key was down when the event 
  62.      * occurred. 
  63.      * @since   JDK1.0
  64.      */
  65.     public static final int CTRL_MASK        = 1 << 1;
  66.  
  67.     /** 
  68.      * This flag indicates that the Meta key was down when the event 
  69.      * occurred. For mouse events, this flag indicates that the right 
  70.      * button was pressed or released. 
  71.      * @since    JDK1.0
  72.      */
  73.     public static final int META_MASK        = 1 << 2;
  74.  
  75.     /** 
  76.      * This flag indicates that the Alt key was down when 
  77.      * the event occurred. For mouse events, this flag indicates that the 
  78.      * middle mouse button was pressed or released. 
  79.      * @since   JDK1.0
  80.      */
  81.     public static final int ALT_MASK        = 1 << 3;
  82.  
  83.     /* Action keys */
  84.     
  85.     /** 
  86.      * The Home key, a non-ASCII action key. 
  87.      * @since   JDK1.0
  88.      */
  89.     public static final int HOME        = 1000;
  90.  
  91.     /** 
  92.      * The End key, a non-ASCII action key. 
  93.      * @since   JDK1.0
  94.      */
  95.     public static final int END            = 1001;
  96.  
  97.     /**
  98.      * The Page Up key, a non-ASCII action key. 
  99.      * @since   JDK1.0
  100.      */
  101.     public static final int PGUP        = 1002;
  102.  
  103.     /**
  104.      * The Page Down key, a non-ASCII action key. 
  105.      * @since   JDK1.0
  106.      */
  107.     public static final int PGDN        = 1003;
  108.  
  109.     /**
  110.      * The Up Arrow key, a non-ASCII action key. 
  111.      * @since   JDK1.0
  112.      */
  113.     public static final int UP            = 1004;
  114.  
  115.     /**
  116.      * The Down Arrow key, a non-ASCII action key. 
  117.      * @since   JDK1.0
  118.      */
  119.     public static final int DOWN        = 1005;
  120.  
  121.     /**
  122.      * The Left Arrow key, a non-ASCII action key. 
  123.      * @since   JDK1.0
  124.      */
  125.     public static final int LEFT        = 1006;
  126.  
  127.     /**
  128.      * The Right Arrow key, a non-ASCII action key. 
  129.      * @since   JDK1.0
  130.      */
  131.     public static final int RIGHT        = 1007;
  132.  
  133.     /**
  134.      * The F1 function key, a non-ASCII action key.
  135.      * @since   JDK1.0
  136.      */
  137.     public static final int F1            = 1008;
  138.  
  139.     /**
  140.      * The F2 function key, a non-ASCII action key.
  141.      * @since   JDK1.0
  142.      */
  143.     public static final int F2            = 1009;
  144.  
  145.     /**
  146.      * The F3 function key, a non-ASCII action key.
  147.      * @since   JDK1.0
  148.      */
  149.     public static final int F3            = 1010;
  150.  
  151.     /**
  152.      * The F4 function key, a non-ASCII action key.
  153.      * @since   JDK1.0
  154.      */
  155.     public static final int F4            = 1011;
  156.  
  157.     /**
  158.      * The F5 function key, a non-ASCII action key.
  159.      * @since   JDK1.0
  160.      */
  161.     public static final int F5            = 1012;
  162.  
  163.     /**
  164.      * The F6 function key, a non-ASCII action key.
  165.      * @since   JDK1.0
  166.      */
  167.     public static final int F6            = 1013;
  168.  
  169.     /**
  170.      * The F7 function key, a non-ASCII action key.
  171.      * @since   JDK1.0
  172.      */
  173.     public static final int F7            = 1014;
  174.  
  175.     /**
  176.      * The F8 function key, a non-ASCII action key.
  177.      * @since   JDK1.0
  178.      */
  179.     public static final int F8            = 1015;
  180.  
  181.     /**
  182.      * The F9 function key, a non-ASCII action key.
  183.      * @since   JDK1.0
  184.      */
  185.     public static final int F9            = 1016;
  186.  
  187.     /**
  188.      * The F10 function key, a non-ASCII action key.
  189.      * @since   JDK1.0
  190.      */
  191.     public static final int F10            = 1017;
  192.  
  193.     /**
  194.      * The F11 function key, a non-ASCII action key.
  195.      * @since   JDK1.0
  196.      */
  197.     public static final int F11            = 1018;
  198.  
  199.     /**
  200.      * The F12 function key, a non-ASCII action key.
  201.      * @since   JDK1.0
  202.      */
  203.     public static final int F12            = 1019;
  204.  
  205.     /**
  206.      * The Print Screen key, a non-ASCII action key.
  207.      * @since   JDK1.0
  208.      */
  209.     public static final int PRINT_SCREEN    = 1020;
  210.  
  211.     /**
  212.      * The Scroll Lock key, a non-ASCII action key.
  213.      * @since   JDK1.0
  214.      */
  215.     public static final int SCROLL_LOCK        = 1021;
  216.  
  217.     /**
  218.      * The Caps Lock key, a non-ASCII action key.
  219.      * @since   JDK1.0
  220.      */
  221.     public static final int CAPS_LOCK        = 1022;
  222.  
  223.     /**
  224.      * The Num Lock key, a non-ASCII action key.
  225.      * @since   JDK1.0
  226.      */
  227.     public static final int NUM_LOCK        = 1023;
  228.  
  229.     /**
  230.      * The Pause key, a non-ASCII action key.
  231.      * @since   JDK1.0
  232.      */
  233.     public static final int PAUSE        = 1024;
  234.  
  235.     /**
  236.      * The Insert key, a non-ASCII action key.
  237.      * @since   JDK1.0
  238.      */
  239.     public static final int INSERT        = 1025;
  240.  
  241.     /* Non-action keys */
  242.     
  243.     /**
  244.      * The Enter key.
  245.      * @since   JDK1.0
  246.      */
  247.     public static final int ENTER        = '\n';
  248.  
  249.     /**
  250.      * The BackSpace key.
  251.      * @since   JDK1.0
  252.      */
  253.     public static final int BACK_SPACE        = '\b';
  254.  
  255.     /**
  256.      * The Tab key.
  257.      * @since   JDK1.0
  258.      */
  259.     public static final int TAB            = '\t';
  260.  
  261.     /**
  262.      * The Escape key.
  263.      * @since   JDK1.0
  264.      */
  265.     public static final int ESCAPE        = 27;
  266.  
  267.     /**
  268.      * The Delete key.
  269.      * @since   JDK1.0
  270.      */
  271.     public static final int DELETE        = 127;
  272.  
  273.  
  274.     /* Base for all window events. */
  275.     private static final int WINDOW_EVENT     = 200;
  276.  
  277.     /**
  278.      * The user has asked the window manager to kill the window.
  279.      * @since    JDK1.0
  280.      */
  281.     public static final int WINDOW_DESTROY     = 1 + WINDOW_EVENT;
  282.  
  283.     /**
  284.      * The user has asked the window manager to expose the window.
  285.      * @since    JDK1.0
  286.      */
  287.     public static final int WINDOW_EXPOSE     = 2 + WINDOW_EVENT;
  288.  
  289.     /** 
  290.      * The user has asked the window manager to iconify the window.
  291.      * @since    JDK1.0
  292.      */
  293.     public static final int WINDOW_ICONIFY    = 3 + WINDOW_EVENT;
  294.  
  295.     /** 
  296.      * The user has asked the window manager to de-iconify the window.
  297.      * @since    JDK1.0
  298.      */
  299.     public static final int WINDOW_DEICONIFY    = 4 + WINDOW_EVENT;
  300.  
  301.     /**
  302.      * The user has asked the window manager to move the window.
  303.      * @since    JDK1.0
  304.      */
  305.     public static final int WINDOW_MOVED    = 5 + WINDOW_EVENT;
  306.  
  307.     /* Base for all keyboard events. */
  308.     private static final int KEY_EVENT         = 400;
  309.  
  310.     /**
  311.      * The user has pressed a normal key.  
  312.      * @since   JDK1.0
  313.      */
  314.     public static final int KEY_PRESS         = 1 + KEY_EVENT;
  315.  
  316.     /**
  317.      * The user has released a normal key.  
  318.      * @since   JDK1.0
  319.      */
  320.     public static final int KEY_RELEASE     = 2 + KEY_EVENT;
  321.  
  322.     /** 
  323.      * The user has pressed a non-ASCII <em>action</em> key.  
  324.      * The <code>key</code> field contains a value that indicates
  325.      * that the event occurred on one of the action keys, which
  326.      * comprise the 12 function keys, the arrow (cursor) keys,
  327.      * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
  328.      * Caps Lock, Num Lock, Pause, and Insert.
  329.      * @since   JDK1.0
  330.      */
  331.     public static final int KEY_ACTION         = 3 + KEY_EVENT;
  332.  
  333.     /** 
  334.      * The user has released a non-ASCII <em>action</em> key.  
  335.      * The <code>key</code> field contains a value that indicates
  336.      * that the event occurred on one of the action keys, which
  337.      * comprise the 12 function keys, the arrow (cursor) keys,
  338.      * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
  339.      * Caps Lock, Num Lock, Pause, and Insert.
  340.      * @since   JDK1.0
  341.      */
  342.     public static final int KEY_ACTION_RELEASE    = 4 + KEY_EVENT;
  343.  
  344.     /* Base for all mouse events. */
  345.     private static final int MOUSE_EVENT     = 500;
  346.  
  347.     /**
  348.      * The user has pressed the mouse button. The <code>ALT_MASK</code> 
  349.      * flag indicates that the middle button has been pressed. 
  350.      * The <code>META_MASK</code>flag indicates that the 
  351.      * right button has been pressed. 
  352.      * @see     java.awt.Event#ALT_MASK
  353.      * @see     java.awt.Event#META_MASK
  354.      * @since   JDK1.0
  355.      */
  356.     public static final int MOUSE_DOWN         = 1 + MOUSE_EVENT;
  357.  
  358.     /**
  359.      * The user has released the mouse button. The <code>ALT_MASK</code> 
  360.      * flag indicates that the middle button has been released. 
  361.      * The <code>META_MASK</code>flag indicates that the 
  362.      * right button has been released. 
  363.      * @see     java.awt.Event#ALT_MASK
  364.      * @see     java.awt.Event#META_MASK
  365.      * @since   JDK1.0
  366.      */
  367.     public static final int MOUSE_UP         = 2 + MOUSE_EVENT;
  368.  
  369.     /**
  370.      * The mouse has moved with no button pressed. 
  371.      * @since   JDK1.0
  372.      */
  373.     public static final int MOUSE_MOVE         = 3 + MOUSE_EVENT;
  374.  
  375.     /**
  376.      * The mouse has entered a component. 
  377.      * @since   JDK1.0
  378.      */
  379.     public static final int MOUSE_ENTER     = 4 + MOUSE_EVENT;
  380.  
  381.     /**
  382.      * The mouse has exited a component. 
  383.      * @since   JDK1.0
  384.      */
  385.     public static final int MOUSE_EXIT         = 5 + MOUSE_EVENT;
  386.  
  387.     /** 
  388.      * The user has moved the mouse with a button pressed. The 
  389.      * <code>ALT_MASK</code> flag indicates that the middle 
  390.      * button is being pressed. The <code>META_MASK</code> flag indicates 
  391.      * that the right button is being pressed. 
  392.      * @see     java.awt.Event#ALT_MASK
  393.      * @see     java.awt.Event#META_MASK
  394.      * @since   JDK1.0
  395.      */
  396.     public static final int MOUSE_DRAG         = 6 + MOUSE_EVENT;
  397.  
  398.  
  399.     /* Scrolling events */
  400.     private static final int SCROLL_EVENT     = 600;
  401.  
  402.     /** 
  403.      * The user has activated the <em>line up</em>  
  404.      * area of a scroll bar. 
  405.      * @since   JDK1.0
  406.      */
  407.     public static final int SCROLL_LINE_UP    = 1 + SCROLL_EVENT;
  408.  
  409.     /**
  410.      * The user has activated the <em>line down</em>  
  411.      * area of a scroll bar. 
  412.      * @since   JDK1.0
  413.      */
  414.     public static final int SCROLL_LINE_DOWN    = 2 + SCROLL_EVENT;
  415.  
  416.     /**
  417.      * The user has activated the <em>page up</em>  
  418.      * area of a scroll bar. 
  419.      * @since   JDK1.0
  420.      */
  421.     public static final int SCROLL_PAGE_UP    = 3 + SCROLL_EVENT;
  422.  
  423.     /**
  424.      * The user has activated the <em>page down</em>  
  425.      * area of a scroll bar. 
  426.      * @since   JDK1.0
  427.      */
  428.     public static final int SCROLL_PAGE_DOWN    = 4 + SCROLL_EVENT;
  429.  
  430.     /**
  431.      * The user has moved the bubble (thumb) in a scroll bar,
  432.      * moving to an "absolute" position, rather than to
  433.      * an offset from the last postion.
  434.      * @since   JDK1.0
  435.      */
  436.     public static final int SCROLL_ABSOLUTE    = 5 + SCROLL_EVENT;
  437.  
  438.     /**
  439.      * The scroll begin event.
  440.      * @since   JDK1.0
  441.      */
  442.     public static final int SCROLL_BEGIN    = 6 + SCROLL_EVENT;
  443.  
  444.     /**
  445.      * The scroll end event.
  446.      * @since   JDK1.0
  447.      */
  448.     public static final int SCROLL_END            = 7 + SCROLL_EVENT;
  449.     
  450.     /* List Events */
  451.     private static final int LIST_EVENT        = 700;
  452.  
  453.     /**
  454.      * An item in a list has been selected. 
  455.      * @since   JDK1.0
  456.      */
  457.     public static final int LIST_SELECT        = 1 + LIST_EVENT;
  458.  
  459.     /**
  460.      * An item in a list has been deselected. 
  461.      * @since   JDK1.0
  462.      */
  463.     public static final int LIST_DESELECT    = 2 + LIST_EVENT;
  464.  
  465.     /* Misc Event */
  466.     private static final int MISC_EVENT        = 1000;
  467.  
  468.     /**
  469.      * This event indicates that the user wants some action to occur. 
  470.      * @since   JDK1.0
  471.      */
  472.     public static final int ACTION_EVENT    = 1 + MISC_EVENT;
  473.  
  474.     /**
  475.      * A file loading event.
  476.      * @since   JDK1.0
  477.      */
  478.     public static final int LOAD_FILE        = 2 + MISC_EVENT;
  479.  
  480.     /**
  481.      * A file saving event.
  482.      * @since   JDK1.0
  483.      */
  484.     public static final int SAVE_FILE        = 3 + MISC_EVENT;
  485.  
  486.     /**
  487.      * A component gained the focus.
  488.      * @since   JDK1.0
  489.      */
  490.     public static final int GOT_FOCUS        = 4 + MISC_EVENT;
  491.  
  492.     /**
  493.      * A component lost the focus.
  494.      * @since   JDK1.0
  495.      */
  496.     public static final int LOST_FOCUS        = 5 + MISC_EVENT;
  497.     
  498.     /**
  499.      * The target component. This indicates the component over which the 
  500.      * event occurred or with which the event is associated. 
  501.      * @since   JDK1.0
  502.      */
  503.     public Object target;
  504.  
  505.     /**
  506.      * The time stamp.
  507.      * @since   JDK1.0
  508.      */
  509.     public long when;
  510.  
  511.     /**
  512.      * Indicates which type of event the event is, and which 
  513.      * other <code>Event</code> variables are relevant for the event.
  514.      * @since   JDK1.0
  515.      */
  516.     public int id;
  517.  
  518.     /** 
  519.      * The <i>x</i> coordinate of the event. 
  520.      * @since   JDK1.0
  521.      */
  522.     public int x;
  523.  
  524.     /** 
  525.      * The <i>y</i> coordinate of the event. 
  526.      * @since   JDK1.0
  527.      */
  528.     public int y;
  529.  
  530.     /** 
  531.      * The key code of the key that was pressed in a keyboard event. 
  532.      * @since   JDK1.0
  533.      */
  534.     public int key;
  535.  
  536.     /** 
  537.      * The key character that was pressed in a keyboard event. 
  538.      * @since   JDK1.0
  539.      */
  540. //    public char keyChar;
  541.  
  542.     /** 
  543.      * The state of the modifier keys.
  544.      * <p>
  545.      * NOTE:  changing the modifier keys is not recommended, because many
  546.      * native implementations do not recognize modifier changes.  This is
  547.      * especially true when the shift modifier is changed.
  548.      *
  549.      * @since     JDK1.0
  550.      */
  551.     public int modifiers;
  552.  
  553.     /**
  554.      * For <code>MOUSE_DOWN</code> events, this field indicates the 
  555.      * number of consecutive clicks. For other events, its value is 
  556.      * <code>0</code>. 
  557.      * @since   JDK1.0
  558.      */
  559.     public int clickCount;
  560.  
  561.     /**
  562.      * An arbitrary argument of the event. The value of this field 
  563.      * depends on the type of event. 
  564.      * @since   JDK1.0
  565.      */
  566.     public Object arg;
  567.  
  568.     /**
  569.      * The next event. This field is set when putting events into a 
  570.      * linked list. 
  571.      * @since   JDK1.0
  572.      */
  573.     public Event evt;
  574.  
  575.     /* table for mapping old Event action keys to KeyEvent virtual keys. */
  576.     private static final int actionKeyCodes[][] = {
  577.     /*    virtual key              action key   */
  578.         { KeyEvent.VK_HOME,        Event.HOME         },
  579.         { KeyEvent.VK_END,         Event.END          },
  580.         { KeyEvent.VK_PAGE_UP,     Event.PGUP         },
  581.         { KeyEvent.VK_PAGE_DOWN,   Event.PGDN         },
  582.         { KeyEvent.VK_UP,          Event.UP           },
  583.         { KeyEvent.VK_DOWN,        Event.DOWN         },
  584.         { KeyEvent.VK_LEFT,        Event.LEFT         },
  585.         { KeyEvent.VK_RIGHT,       Event.RIGHT        },
  586.         { KeyEvent.VK_F1,          Event.F1           },
  587.         { KeyEvent.VK_F2,          Event.F2           },
  588.         { KeyEvent.VK_F3,          Event.F3           },
  589.         { KeyEvent.VK_F4,          Event.F4           },
  590.         { KeyEvent.VK_F5,          Event.F5           },
  591.         { KeyEvent.VK_F6,          Event.F6           },
  592.         { KeyEvent.VK_F7,          Event.F7           },
  593.         { KeyEvent.VK_F8,          Event.F8           },
  594.         { KeyEvent.VK_F9,          Event.F9           },
  595.         { KeyEvent.VK_F10,         Event.F10          },
  596.         { KeyEvent.VK_F11,         Event.F11          },
  597.         { KeyEvent.VK_F12,         Event.F12          },
  598.         { KeyEvent.VK_PRINTSCREEN, Event.PRINT_SCREEN },
  599.         { KeyEvent.VK_SCROLL_LOCK, Event.SCROLL_LOCK  },
  600.         { KeyEvent.VK_CAPS_LOCK,   Event.CAPS_LOCK    },
  601.         { KeyEvent.VK_NUM_LOCK,    Event.NUM_LOCK     },
  602.         { KeyEvent.VK_PAUSE,       Event.PAUSE        },
  603.         { KeyEvent.VK_INSERT,      Event.INSERT       }
  604.     };
  605.  
  606.     // This field controls whether or not the event is sent back
  607.     // down to the peer once the target has processed it -
  608.     // false means it's sent to the peer, true means it's not.
  609.     private boolean consumed = false;
  610.  
  611.     /*
  612.      * JDK 1.1 serialVersionUID 
  613.      */
  614.     private static final long serialVersionUID = 5488922509400504703L;
  615.  
  616.     /**
  617.      * Creates an instance of <code>Event</code> with the specified target 
  618.      * component, time stamp, event type, <i>x</i> and <i>y</i> 
  619.      * coordinates, keyboard key, state of the modifier keys, and 
  620.      * argument. 
  621.      * @param     target     the target component.
  622.      * @param     when       the time stamp.
  623.      * @param     id         the event type.
  624.      * @param     x          the <i>x</i> coordinate.
  625.      * @param     y          the <i>y</i> coordinate.
  626.      * @param     key        the key pressed in a keyboard event.
  627.      * @param     modifiers  the state of the modifier keys.
  628.      * @param     arg        the specified argument.
  629.      * @since     JDK1.0
  630.      */
  631.     public Event(Object target, long when, int id, int x, int y, int key,
  632.          int modifiers, Object arg) {
  633.     this.target = target;
  634.     this.when = when;
  635.     this.id = id;
  636.     this.x = x;
  637.     this.y = y;
  638.     this.key = key;
  639.     this.modifiers = modifiers;
  640.     this.arg = arg;
  641.     this.data = 0;
  642.     this.clickCount = 0;
  643.         switch(id) {
  644.           case ACTION_EVENT:
  645.           case WINDOW_DESTROY:
  646.           case WINDOW_ICONIFY:
  647.           case WINDOW_DEICONIFY:
  648.           case WINDOW_MOVED:
  649.           case SCROLL_LINE_UP:
  650.           case SCROLL_LINE_DOWN:
  651.           case SCROLL_PAGE_UP:
  652.           case SCROLL_PAGE_DOWN:
  653.           case SCROLL_ABSOLUTE:
  654.           case SCROLL_BEGIN:
  655.           case SCROLL_END:
  656.           case LIST_SELECT:
  657.           case LIST_DESELECT:
  658.             consumed = true; // these types are not passed back to peer
  659.             break;
  660.           default:
  661.         }
  662.     }
  663.  
  664.     /**
  665.      * Creates an instance of <code>Event</code>, with the specified target 
  666.      * component, time stamp, event type, <i>x</i> and <i>y</i> 
  667.      * coordinates, keyboard key, state of the modifier keys, and an 
  668.      * argument set to <code>null</code>. 
  669.      * @param     target     the target component.
  670.      * @param     when       the time stamp.
  671.      * @param     id         the event type.
  672.      * @param     x          the <i>x</i> coordinate.
  673.      * @param     y          the <i>y</i> coordinate.
  674.      * @param     key        the key pressed in a keyboard event.
  675.      * @param     modifiers  the state of the modifier keys.
  676.      * @since    JDK1.0
  677.      */
  678.     public Event(Object target, long when, int id, int x, int y, int key, int modifiers) {
  679.     this(target, when, id, x, y, key, modifiers, null);
  680.     }
  681.  
  682.     /**
  683.      * Creates an instance of <code>Event</code> with the specified  
  684.      * target component, event type, and argument. 
  685.      * @param     target     the target component.
  686.      * @param     id         the event type.
  687.      * @param     arg        the specified argument.
  688.      * @since     JDK1.0
  689.      */
  690.     public Event(Object target, int id, Object arg) {
  691.     this(target, 0, id, 0, 0, 0, 0, arg);
  692.     }
  693.  
  694.     /** 
  695.      * Translates this event so that its <i>x</i> and <i>y</i> 
  696.      * coordinates are increased by <i>dx</i> and <i>dy</i>, 
  697.      * respectively. 
  698.      * <p>
  699.      * This method translates an event relative to the given component. 
  700.      * This involves, at a minimum, translating the coordinates into the
  701.      * local coordinate system of the given component. It may also involve
  702.      * translating a region in the case of an expose event.
  703.      * @param     dx     the distance to translate the <i>x</i> coordinate.
  704.      * @param     dy     the distance to translate the <i>y</i> coordinate.
  705.      * @since     JDK1.0
  706.      */
  707.     public void translate(int x, int y) {
  708.     this.x += x;
  709.     this.y += y;
  710.     }
  711.  
  712.     /**
  713.      * Checks if the Shift key is down.
  714.      * @return    <code>true</code> if the key is down; 
  715.      *            <code>false</code> otherwise.
  716.      * @see       java.awt.Event#modifiers
  717.      * @see       java.awt.Event#controlDown
  718.      * @see       java.awt.Event#metaDown
  719.      * @since     JDK1.0
  720.      */
  721.     public boolean shiftDown() {
  722.     return (modifiers & SHIFT_MASK) != 0;
  723.     }
  724.  
  725.     /**
  726.      * Checks if the Control key is down.
  727.      * @return    <code>true</code> if the key is down; 
  728.      *            <code>false</code> otherwise.
  729.      * @see       java.awt.Event#modifiers
  730.      * @see       java.awt.Event#shiftDown
  731.      * @see       java.awt.Event#metaDown
  732.      * @since     JDK1.0
  733.      */
  734.     public boolean controlDown() {
  735.     return (modifiers & CTRL_MASK) != 0;
  736.     }
  737.  
  738.     /**
  739.      * Checks if the Meta key is down.
  740.      * @return    <code>true</code> if the key is down; 
  741.      *            <code>false</code> otherwise.
  742.      * @see       java.awt.Event#modifiers
  743.      * @see       java.awt.Event#shiftDown
  744.      * @see       java.awt.Event#controlDown
  745.      * @since     JDK1.0
  746.      */
  747.     public boolean metaDown() {
  748.     return (modifiers & META_MASK) != 0;
  749.     }
  750.  
  751.     void consume() {
  752.         switch(id) {
  753.           case KEY_PRESS:
  754.           case KEY_RELEASE:
  755.           case KEY_ACTION:
  756.           case KEY_ACTION_RELEASE:
  757.               consumed = true;
  758.               break;
  759.           default:
  760.               // event type cannot be consumed
  761.         }
  762.     }
  763.  
  764.     boolean isConsumed() {
  765.         return consumed;
  766.     }
  767.  
  768.     /*
  769.      * Returns the integer key-code associated with the key in this event,
  770.      * as described in java.awt.Event.  
  771.      */
  772.     static int getOldEventKey(KeyEvent e) {
  773.         int keyCode = e.getKeyCode();
  774.         for (int i = 0; i < actionKeyCodes.length; i++) {
  775.             if (actionKeyCodes[i][0] == keyCode) {
  776.                 return actionKeyCodes[i][1];
  777.             }
  778.         }
  779.         return (int)e.getKeyChar();
  780.     }
  781.  
  782.     /*
  783.      * Returns a new KeyEvent char which corresponds to the int key
  784.      * of this old event.
  785.      */
  786.     char getKeyEventChar() {
  787.        for (int i = 0; i < actionKeyCodes.length; i++) {
  788.             if (actionKeyCodes[i][1] == key) {
  789.                 return KeyEvent.CHAR_UNDEFINED;
  790.             }
  791.        }
  792.        return (char)key;
  793.     }
  794.  
  795.     /**
  796.      * Returns the parameter string representing this event. 
  797.      * This string is useful for debugging.
  798.      * @return    the parameter string of this event.
  799.      * @since     JDK1.0 
  800.      */
  801.     protected String paramString() {
  802.     String str = "id=" + id + ",x=" + x + ",y=" + y;
  803.     if (key != 0) {
  804.         str += ",key=" + key;
  805.     }
  806.     if (shiftDown()) {
  807.         str += ",shift";
  808.     }
  809.     if (controlDown()) {
  810.         str += ",control";
  811.     }
  812.     if (metaDown()) {
  813.         str += ",meta";
  814.     }
  815.     if (target != null) {
  816.         str += ",target=" + target;
  817.     }
  818.     if (arg != null) {
  819.         str += ",arg=" + arg;
  820.     }
  821.     return str;
  822.     }
  823.  
  824.     /**
  825.      * Returns a representation of this event's values as a string.
  826.      * @return    a string that represents the event and the values
  827.      *                 of its member fields.
  828.      * @see       java.awt.Event#paramString
  829.      * @since     JDK1.1
  830.      */
  831.     public String toString() {
  832.     return getClass().getName() + "[" + paramString() + "]";
  833.     }
  834. }
  835.